//
//  HWMineItemCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/8/23.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWMineItemCell: UICollectionViewCell {
    var imageView:UIImageView!
    var titleLabel:UILabel!
    var model:HWMineNavDataModel? {
        didSet {
            imageView.kf.setImage(with: URL(string: model?.icon ?? ""))
            titleLabel.text = model?.name
            
            if (model?.type ?? "") == "0" {
                imageView.snp.updateConstraints { make in
                    make.width.height.equalTo(44*widthScale)
                }
                
                titleLabel.snp.updateConstraints { make in
                    make.left.equalTo(10*widthScale)
                    make.right.equalTo(-10*widthScale)
                }
            } else {
                imageView.snp.updateConstraints { make in
                    make.width.height.equalTo(22*widthScale)
                }
                titleLabel.snp.updateConstraints { make in
                    make.left.equalTo(0)
                    make.right.equalTo(0)
                }
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWMineItemCell {
    private func initUI() -> Void {
        
        imageView = UIImageView()
        imageView.backgroundColor = .clear
        contentView.addSubview(imageView)
        
        titleLabel = HWLabel.createLabel(title: "", color: "#333333", font: 13*widthScale)
        titleLabel.textAlignment = .center
        contentView.addSubview(titleLabel)
    }
    
    private func initFrame() -> Void {
        imageView.snp.makeConstraints { make in
            make.width.height.equalTo(22*widthScale)
            make.centerX.equalToSuperview()
            make.top.equalTo(22*widthScale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.height.equalTo(18*widthScale).priority(.high)
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(imageView.snp.bottom).offset(9*widthScale).priority(.high)
        }
    }
}
